package com.lhf.warnsend.warnsendjson.message.util;

import sun.misc.BASE64Encoder;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * <p></p>
 *
 * @author liuhf
 * @createTime 2021/9/3 10:31
 * @since 1.0
 */
public class MD5Ciphertext implements Ciphertext {
    @Override
    public String encryption(String source) {
        try {
            MessageDigest instance = MessageDigest.getInstance("md5");
            byte[] digest = instance.digest(source.getBytes(StandardCharsets.UTF_8));
            return new BASE64Encoder().encode(digest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String decrypt(String ciphertext) {
        return null;
    }
}
